package com.killer.controller;

import com.killer.pojo.Order;
import com.killer.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @RequestMapping("/add")
    public String addOrder() {
        Order order = orderService.addOrder();
        return "添加订单成功，请在15分钟之内支付，订单ID为:"+order.getId();
    }

    @RequestMapping("/pay/{orderId}")
    public Object payOrder(@PathVariable Long orderId){
        boolean result=orderService.payOrder(orderId);
        if (result) {
            return "订单id:" + orderId + "支付成功";
        }else{
            //已经过期导致支付失败的返回历史过期订单记录
            return orderService.listExpireOrders();
        }
    }
}
